import complex_query from '@dfeidao/atom-nodejs/db/complex-query';
import query from '@dfeidao/atom-nodejs/db/query';
import { IncomingHttpHeaders } from 'http';
import { productid,systemid } from '../../atom/config';
// 这里是查询
interface Message {
	filter: {
		project_no: string,
		is_resident: string
	};
}
export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders) {
	if (message.filter.is_resident !== '' && message.filter.project_no === '') {
        // tslint:disable-next-line:no-shadowed-variable
        const query = complex_query(action_id, session_id, systemid);
	    const dt = await query
	    .add_field('project_personnel', 'is_resident', 'is_resident')
	    .add_field('project_personnel', 'project_name', 'project_name')
	    .add_field('project_personnel', 'project_no', 'project_no')
        .add_field('project_personnel', 'pub_user_no', 'pub_user_no')
	    .where_eq('project_personnel', 'is_resident', message.filter.is_resident)
	    .page(20, 1)
		.exec();
		return{dt};
	}
	if ( message.filter.is_resident !== '' && message.filter.project_no !== '') {
		// tslint:disable-next-line:no-shadowed-variable
		const query = complex_query(action_id, session_id, systemid);
	    const dt = await query
	    .add_field('project_personnel', 'is_resident', 'is_resident')
	    .add_field('project_personnel', 'project_name', 'project_name')
	    .add_field('project_personnel', 'project_no', 'project_no')
		.add_field('project_personnel', 'pub_user_no', 'pub_user_no')
		.where_eq('project_personnel', 'is_resident', message.filter.is_resident)
		.where_eq('project_personnel', 'project_no', message.filter.project_no)
	    .page(20, 1)
		.exec();
		return{dt};
	}
	if ( message.filter.is_resident === '' && message.filter.project_no !== '') {
		// tslint:disable-next-line:no-shadowed-variable
		const query = complex_query(action_id, session_id, systemid);
	    const dt = await query
	    .add_field('project_personnel', 'is_resident', 'is_resident')
	    .add_field('project_personnel', 'project_name', 'project_name')
	    .add_field('project_personnel', 'project_no', 'project_no')
		.add_field('project_personnel', 'pub_user_no', 'pub_user_no')
	    .where_eq('project_personnel', 'project_no', message.filter.project_no)
	    .page(20, 1)
		.exec();
		return{dt};
	}
	if ( message.filter.is_resident === '' && message.filter.project_no === '') {
		const ppp = query(action_id, session_id, systemid);
		ppp.prepare('project_personnel', ['is_resident', 'project_name','project_no','pub_user_no'], {productid}, 200,  1, [], []);
		const [dt] = await ppp.exec();
		return {dt};
	}


}
